﻿<%@ WebHandler Language="C#" Class="CheckCarrs" %>
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using MySql.Data.MySqlClient;
using LdExpress;

public class CheckCarrs : IHttpHandler
{

    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/plain";
        string stPol = "";
        string stPod = "";
        string stCarrId = "";
        if ((context.Request.QueryString.Get("POL") != "") && (context.Request.QueryString.Get("POL") != null))
        {
            stPol = context.Request.QueryString.Get("POL");
        }
        if ((context.Request.QueryString.Get("POD") != "") && (context.Request.QueryString.Get("POD") != null))
        {
            stPod = context.Request.QueryString.Get("POD");
        }
        if ((context.Request.QueryString.Get("CarrId") != "") && (context.Request.QueryString.Get("CarrId") != null))
        {
            stCarrId = context.Request.QueryString.Get("CarrId");
        }
        string stVal = "";
        string sqlCommand = "";
        if (stPol.Length > 0)
        {
            sqlCommand = "Select * from tbl_schedules where PortToID=" + stPol + " AND PortFromID=" + stPod + " AND CarrID=" + stCarrId;
            DataSet ds = DBModule.ExecuteQuery(sqlCommand, null, null);

            if (ds.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    if (stVal != "") stVal += "\n";                       
                    stVal += dr["Service"].ToString().ToUpper();
                    if (dr["TS1"].ToString().Length > 0)
                        stVal += " " + dr["TS1"].ToString().ToUpper();
                    if (dr["TS2"].ToString().Length > 0)
                        stVal += " " + dr["TS2"].ToString().ToUpper();
                    if (dr["Mon"].ToString().Length > 0)
                        stVal += " MON " + dr["Mon"].ToString().ToUpper();
                    if (dr["Tue"].ToString().Length > 0)
                        stVal += " TUE " + dr["Tue"].ToString().ToUpper();
                    if (dr["Web"].ToString().Length > 0)
                        stVal += " WEB " + dr["Web"].ToString().ToUpper();
                    if (dr["thu"].ToString().Length > 0)
                        stVal += " THU " + dr["thu"].ToString().ToUpper();
                    if (dr["Fri"].ToString().Length > 0)
                        stVal += " FRI " + dr["Fri"].ToString().ToUpper();
                    if (dr["Sat"].ToString().Length > 0)
                        stVal += " SAT " + dr["Sat"].ToString().ToUpper();
                    if (dr["Sun"].ToString().Length > 0)
                        stVal += " SUN " + dr["Sun"].ToString().ToUpper();
                    if (dr["LastUpdate"].ToString().Length > 0)
                        stVal += " Update " + DateTime.Parse(dr["LastUpdate"].ToString()).ToString("ddMMyyyy");
                }

            }
            else { stVal += "Không tìm thấy lịch tàu này."; }
        }
        context.Response.Cache.SetExpires(DateTime.Now.AddSeconds(0));
        context.Response.Cache.SetCacheability(HttpCacheability.Public);
        context.Response.Write(stVal);
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

}